package com.spring.study.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.spring.study.pojo.Emp;
import com.spring.study.service.EmpService;

import com.spring.study.utils.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/emp")
@Slf4j
public class EmpController {

//    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private EmpService empService;

    @RequestMapping(value = "/find",method = RequestMethod.GET)

    public ResultUtil<PageInfo<Emp>> findAllEmp(@RequestParam(value = "page",defaultValue = "1") Integer page,
                                                @RequestParam(value = "size",defaultValue = "10") Integer size){
        log.info("执行find方法");
        return  ResultUtil.success(empService.findAllEmp(page,size));
//        logger.info("执行find方法");
//        return empService.findAllEmp();
    }

    @RequestMapping(value = "/find/{id}",method = RequestMethod.GET)
    public Emp findById(@PathVariable("id") Integer empId){
        log.info("This empId:{}",empId);
        return empService.findById(empId);
    }

    //购买商品测试事务
    @RequestMapping(value = "/buyGood",method = RequestMethod.POST)
    public ResultUtil<String> buyGood(@RequestParam("empId") Integer empId,@RequestParam("goodId") Integer goodId,@RequestParam("num") Integer num){
        empService.buyGood(empId,goodId,num);
        return ResultUtil.success();
    }
}
